<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org">
<head th:replace="components/head :: head(~{:: title}, ~{:: link})">
    <meta charset="UTF-8">
    <title>分类管理</title>
    <link rel="stylesheet" href="/css/wen.css">
</head>
<body>
<!-- Header -->
<header th:replace="_fragments/nav :: navbar"></header>
<!-- End Header -->


<!-- Content -->
<div class="container">
    <div class="alert alert-danger" role="alert"
         th:if="${errInfo != null}" th:text="${errInfo}"></div>
    <div class="alert alert-success" role="alert"
         th:if="${successInfo != null}" th:text="${successInfo}"></div>
    <!-- Body -->
    <div th:if="${type != null}">
        <h1>修改分类</h1>
        <form th:action="@{'/admin/type/edit/' + ${type.getId()}}" method="post">
            <div class="form-group">
                <label for="new_type_name">分类名称</label>
                <input id="new_type_name" type="text" class="form-control" name="name"
                       placeholder="类型名称"  th:value="${type.getName()}">
            </div>
            <input type="submit" value="Submit" class="btn btn-default">
        </form>
    </div>

    <div class="container" th:if="${type == null}">
        <h1 style="margin: 40px 0 40px 0;">Type Management</h1>
        <table class="table table-striped">
            <thead>
            <tr>
                <td>序号</td>
                <td>id</td>
                <td>分类名</td>
                <td>操作</td>
            </tr>
            </thead>
            <tbody>
            <tr th:each="item, iterStat : ${page.content}">
                <td th:text="${iterStat.count}"></td>
                <td th:text="${item.id}"></td>
                <td th:text="${item.name}"></td>
                <td>
                    <a th:href="@{'/admin/type/edit/' + ${item.id}}" class="btn btn-default">修改</a>
                    <a th:href="@{'/admin/type/delete/' + ${item.id}}" class="btn btn-default">删除</a>
                </td>
            </tr>
            </tbody>
        </table>
        <!-- Pagination -->
        <nav aria-label="Page navigation" class="col-md-offset-4 col-lg-offset-4col-xl-offset-4">
            <ul class="pagination">
                <li class="disabled" th:if="${page.first == true}">
                <span>
                    <span aria-hidden="true">&laquo;</span>
                </span>
                </li>
                <li th:if="${page.first == false}">
                    <a th:href="@{/admin/type(page=${page.number} - 1)}" aria-label="Next">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
                <li class="disabled" th:if="${page.last == true}">
                <span>
                    <span aria-hidden="true">&raquo;</span>
                </span>
                </li>
                <li th:if="${page.last == false}">
                    <a th:href="@{/admin/type(page=${page.number} + 1)}" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </ul>
        </nav>
        <!-- End Pagination -->
    </div>

    <div th:if="${type == null}">
        <h1>新增分类</h1>
        <form action="/admin/type/add" method="post">
            <div class="form-group">
                <label for="type_name">分类名称</label>
                <input id="type_name" type="text" class="form-control" name="name" placeholder="类型名称">
            </div>
            <input type="submit" value="Submit" class="btn btn-default">
        </form>
    </div>
    <!-- End Body -->

    <!-- Footer -->
    <div th:replace="components/footer :: footer"></div>
    <!-- End Footer -->
</div>
<!-- End Content -->
</body>
</html>
